package com.example.yls.demoa;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class MainActivity extends AppCompatActivity {
    private Button reg;
    private Button login;
    private Button info;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iniBtn();
    }

    private void iniBtn() {
        reg= findViewById(R.id.btn_reg);
        login=findViewById(R.id.btn_login);
        info=findViewById(R.id.btn_info);
        
        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 BmobUser bmobUser=new BmobUser();
                bmobUser.setUsername("张一山");
                bmobUser.setPassword("0663");
                bmobUser.signUp(new SaveListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        if (e==null){
                            toast("注册成功"+bmobUser.getUsername());
                        }else {
                            toast("注册失败"+e.getMessage());
                        }

                    }
                });
            }
        });
    }

    private void toast(String s) {
        Toast.makeText(MainActivity.this,s,Toast.LENGTH_SHORT).show();

    }
}
